/**
 * Created by cyf on 15-12-1.
 * 主界面初始化ui
 */
(function() {
    qxchat.Index = Index;
    var EXTEND = null; //是否需要继承
    function Index() {
        if (EXTEND) {
            EXTEND.apply(this, arguments);
        }
        this.init();
        this._WindowSize._win.moveTo(screen.availLeft + screen.availWidth - 400, 80);
        this._WindowSize._win.show();
    }

    Index.prototype = {
        constructor: Index,
        init: function() {
            this._WindowSize = new qxchat.WindowSize();
            var self = this;
            //联系人/最近联系人等点击事件
            $('.qx-xuan li').click(function() {
                $(this).addClass('qx-xuan-li').siblings().removeClass('qx-xuan-li')
            })
        }
    }
})();
/**
 * Created by cyf on 15-12-1.
 * 初始化窗口的三个按钮
 */
(function() {

    qxchat.WindowSize = WindowSize;
    var EXTEND = null; //是否需要继承
    function WindowSize() {
        if (EXTEND) {
            EXTEND.apply(this, arguments);
        }
        this._sizeFlag = true;
        this._gui = require('nw.gui');
        this._win = this._gui.Window.get();
        this.init();
        var self = this;
        $('.minisizeBtn').bind('click', function() {
            self.minimize();
            global.tray.isShowWindow = false;
        });
        $('.plusBtn').bind('click', function() {
            self.maxToggle();
        });
        $('.closeBtn').bind('click', function() {
            self.close();
        });

    }
    WindowSize.prototype = {
        constructor: WindowSize,
        init: function() {

        },
        minimize: function() {
            this._win.hide();
            this._sizeFlag = true;
        },
        maxToggle: function() {
            if (this._sizeFlag) {
                this._win.maximize();
                this._sizeFlag = false;
            } else {
                this._win.unmaximize();
                this._sizeFlag = true;
            }
        },
        close: function() {
            try {
                var gui = require('nw.gui');
                gui.App.closeAllWindows();
            } catch(e) {
                var gui = require('nw.gui');
                gui.App.quit();
            }
        }
    }
})();


(function() {
    qxchat.Stat = Stat;
    var EXTEND = null;

    function Stat() {
        if (EXTEND) {
            EXTEND.apply(this, arguments);
        }

        this._subHolder = $('#qx-main-u .sub-holder');

        this._lis = $('#qx-main-u .dropdown-menu li');

        var self = this;

        this._lis.click(function() {
            var index = self._lis.index($(this)[0]);
            self.setStatus(index);
        });
    }

    Stat.prototype = {
        init: function() {

        },
        setStatus: function(index) {
            switch (index) {
                case 0:
                    {
                        this._subHolder.css('background-position', '1px 1px');
                        break;
                    }
                case 1:
                    {
                        this._subHolder.css('background-position', '1px -143px');
                        break;
                    }
                case 2:
                    {
                        break;
                    }
                case 3:
                    {
                        this._subHolder.css('background-position', '1px -116px');
                        break;
                    }
            }
        }
    }
})();